Greater than (>) Comparison Operator
The “greater than” (>) operator is a comparison operator used in programming languages to determine whether the value or expression on the left of the operand is greater than the value or expression on the right.
Example of Greater than (>) Comparison Operator:
Here are the example of Greater than (>) Operator in different language:
#include <iostream>
using namespace std;
int main()
{
int x = 5;
int y = 10;
if (x > y) {
cout << "x is greater than y" << endl;
}
else {
cout << "x is not greater than y" << endl;
}
return 0;
}
#include <stdio.h>
int main()
{
int x = 5;
int y = 10;
if (x > y) {
printf("x is greater than y\n");
}
else {
printf("x is not greater than y\n");
}
return 0;
}
public class Main {
public static void main(String[] args)
{
int x = 5;
int y = 10;
if (x > y) {
System.out.println("x is greater than y");
}
else {
System.out.println("x is not greater than y");
}
}
}
let x = 5;
let y = 10;
if (x > y) {
console.log("x is greater than y");
} else {
console.log("x is not greater than y");
}
x = 5
y = 10
if x > y:
print("x is greater than y")
else:
print("x is not greater than y")
Output
x is not greater than y
Comparison Operators in Programming
Comparison Operators in programming are used to compare values and determine their relationship, such as equality, inequality, greater than, less than, etc. They evaluate expressions and return a Boolean value (true or false) based on the comparison result, crucial for decision-making in conditional statements and loops.
Table of Content
- What is a Comparison Operator?
- Common Comparison Operators
- Equal to (==) Comparison Operator
- Not equal to (!=) Comparison Operator
- Greater than (>) Comparison Operator
- Greater than or equal to (>=) Comparison Operator
- Less than (<) Comparison Operator
- Less than or equal to (<=) Comparison Operator